<template>
  <div>
    <!--条件筛选-->
    <!-- <TopFilter :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter> -->
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="lhmIcomeStatisticsa"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isSelectColumn="boolear"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
      <!--列操作-->
      <template slot="controls">
        <el-button size="small" type="primary"  @click="openSaleSingleModel">新增</el-button>
        <el-button size="small" type="primary"  @click="delectHandle">删除</el-button>
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visibleSaleSingle"
      title="新增发票"
      :closable="true"
      :destroyOnClose="true"
      :maskClosable="true"
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <SaleSingleModel @close="closeHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="operateTipVisible" destroyOnClose />
     <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关闭</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getQueryAccountsModel } from '@/api/repair/queryStatistics/queryAccounts';
import SaleSingleModel from './saleSingleModel';
export default {
  name: 'LHMIcomeStatisticsa',
  components: {
    SaleSingleModel
  },
  mixins: [dictionary],
  props: {
    rowData: {
      type: Object,
      default: () => ({})
    }
  },

  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: {},
      visible: false,
      visible1: false,
      boolear:false,
      visibleSaleSingle: false,
      operateTipVisible: false,
      dialogTitle: '',
      fetchApi: getQueryAccountsModel,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      tableData: [],
      ids: []
    };
  },
   created() {
    this.init();
  },

  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'DATE',
          label: '查询日期',
          fieldName: 'BALANCE_TIME',
          placeholder: '选择日期'
        },

      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
         {
          title: '年月',
          dataIndex: 'WTS',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd HH:mm:ss'
        },
        {
          title: '金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发票日期',
          dataIndex: 'BALANCE_TIME',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '发票号',
          dataIndex: 'BALANCE_HANDLER',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    selectData(val) {
      this.tableData = val;
    },
     openSaleSingleModel() {
      this.visibleSaleSingle = true;
    },
    addHandle() {
      // 新建
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit'; // 编辑
      this.formData = row;
      this.showHandler();
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    init() {

    },
      closeHandler(val, type) {
      // 关闭
      this.visibleSaleSingle = val;
      if (type === 'refresh') {
        // 重新加载
        this.visibleSaleSingle = val;
        this.fetchParams = { ...this.fetchParams };
      }
    },
    async saveDialog() {
      let res = {};
      const [err, data] = await this.$refs.formPanel.GET_FORM_DATA(); // 获取from改变时整个表单的值
      console.log('data', data);
      if (err) return;
      res = await addMaintionClaimReceipt({ ...data });
      if (res.resultCode === 200) {
        // / this.isdisabled = false; //处理库存的按钮是否显示
        this.closeDialog('refresh');
        return this.$notify({
          title: '提示信息',
          message: '保存成功',
          type: 'success'
        });
      }
    },
     async delectHandle() {
      if (!this.selectedRow.length) {
        return this.$notify({
          title: '提示信息',
          message: '请选择数据',
          type: 'error'
        });
      }
      await this.$confirm('已选择数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      });
      console.log(999);
      await this.delectHandle1();
    },
    async delectHandle1() {
      // 取出数据id
      this.ids = this.selectedRow.map(x => x.receiptId);
      let res = await delectMaintionClaimReceipt({ ids: this.ids.join(',') });
      console.log(res);
      // 判断结果
      if (res.resultCode === 200) {
        console.log(res.data);
        if (res.data) {
          this.fetchParams = { ...this.fetchParams };
          return this.$notify({
            title: '提示信息',
            message: '删除成功',
            type: 'success'
          });
        }
      }
    },
    showHandler() {
      // 显示
      this.dialogTitle = `更改历史`;
      this.visible = true;
    },
    closeDialog(param) {
      this.$emit('close', false, param);
    }
  }
};
</script>

<style lang="less" scoped></style>
